//
//  JMNetworkTools.m
//  仿生物无忧
//
//  Created by 彭继宗 on 15/12/5.
//  Copyright © 2015年 彭继宗. All rights reserved.
//

#import "JMNetworkTools.h"




@interface JMNetworkTools ()

@end

@implementation JMNetworkTools


//单例
+ (instancetype)shareNetworkTools
{
    static id instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        instance = [[self alloc] init];
        
        //增加text/plain 类型
        NSSet *types = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/plain", @"text/html",nil];
        
        [[instance responseSerializer] setAcceptableContentTypes:types];
        
    });
    
    return instance;
}


- (void)demoJson
{
    
    //设置url
    NSString *urlString = @"http://localhost/Others/demo.json";
    //设置参数
    NSDictionary *parameters =
    @{@"action":@"index",
      @"authKey":@"f291b9423b9c3f10dff75d169fccc299",
      @"device":@4,
      @"page":@1,
      @"pageSize":@10,
      @"type":@"yixue"};
    
    //通过post发送登陆请求
    [self POST:urlString parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        
        //调用block
//        finishBlock(responseObject,nil);
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"error = %@",error);
        
        
    }];
}


- (void)loadTopViewPicWithFinish:(FinishCallBack)finishBlock
{
    //设置url
    NSString *urlString = @"http://www.swwy.com/app/android/index.php";
    //设置参数
    NSDictionary *parameters =
                                @{@"action":@"index",
                                  @"authKey":@"f291b9423b9c3f10dff75d169fccc299",
                                  @"device":@4,
                                  @"page":@1,
                                  @"pageSize":@10,
                                  @"type":@"yixue"};
    
    //通过post发送登陆请求
    [self POST:urlString parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        
        //调用block
        finishBlock(responseObject,nil);
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"error = %@",error);
    }];
    
    
}


@end
